ResourceFork Class
ResourceFork Class objects are used to read and write data to resources. You can add resource files to the Project Editor (files of type "rsrc").
More information available in parent classes: Object
Notes
With one exception, access to the resourcefork is supported only on Macintosh. Check the value of the TargetMacOS constant before attempting to access the resourcefork.
The one exception is that you can add custom cursors to a project using the CURS resource and access them from a Windows build. See the Notes for the MouseCursor class and the section "Custom Cursors in Windows Applications" in the User's Guide.
In built applications, all of the fields in the Get Info area of the Build Application dialog box are saved in a standard 'vers' resource. You can access this information -- such as version number, region code, and release level -- using the GetResource method of the ResourceFork class.
If you use resource numbers that conflict with internal REALbasic resources, unpredictable results may occur. One way to avoid resource ID conflicts is to choose high values, like 1128 instead of 128.
An alternate way of adding custom icons to your built application is to put your icon data (including 'icns' 32-bit icons) in a resources file that you add to your project. These icons will overwrite the icon resources supplied by REALbasic itself.
More information on the resource attribute properties (ResourceLocked, ResourcePreLoad, ResourceProtected, ResourcePurgeable, ResourceSysHeap) can be found in Apple Computer's Inside Macintosh series.
Examples
This example sets the locked attribute of a PICT resource whose ID is 128:
rf= GetFolderItem("MyApp").OpenResourceFork
rf.ResourceLocked("PICT",128)= True
This example checks to see if the purgable property is set
rf= GetFolderItem("MyApp").OpenResourceFork
If rf.ResourcePurgeable("PICT",128) Then
Beep
MsgBox "This resource is purgeable."
End If
:
This example opens the project's resource fork. If you have added a resource file to your project, you can use this technique to access your resource file (assuming that the compiled application is running on Macintosh)
:
This example gets the desktop application icon for Photoshop® and displays it in a Canvas control.
Dim f as FolderItem
Dim p as Picture
f= GetFolderItem("Photoshop")
If f <> Nil then
rf=f.OpenResourceFork
If rf <> Nil then
p=rf.Geticl(128)
Canvas1.backdrop=p
Else
MsgBox "Resource not found!"
End if
Else
MsgBox "File not found!"
End if
This example loads a cursor from the Photoshop application and uses it as the application's cursor.
Dim m as MouseCursor
DimFolderItem
f= GetFolderItem("Photoshop")
If f <> Nil then
rf=f.OpenResourceFork
If rf <> Nil then
m=rf.GetCursor(1525)
App.MouseCursor=m
Else
MsgBox "Resource not found!"
End if
Else
MsgBox "File not found!"
End if
See Also
App, Cursors, System objects; MouseCursor, Window class.